/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package swym.protocol;

import java.io.Serializable;

/**
 *
 * @author mschaefer
 */
public class ActionMessage implements Serializable
{
    private int requestID;
    private String userName;
    private String clientName;
    private String type;
    private Object payload;
    
    // true if the client wants this connection to be used for
    // alerts to the client 
    private boolean indicatesUpdateConnection; 
    
    
    // These are the expected values for type
    public static final String TYPE_FILE     = "file";
    public static final String TYPE_REGISTER = "register";
    public static final String TYPE_CONFIRM  = "confirm";
    public static final String TYPE_CLOSE    = "close";
    public static final String TYPE_LOGIN    = "login";
    public static final String TYPE_UPDATE   = "update";
    public static final String TYPE_CLIENT_QUERY = "client query";
    public static final String TYPE_ACTION_QUERY = "file action query";
    
    /**
     * No default constructing.
     */
    private ActionMessage() {}
    
    protected ActionMessage( String user, String client, String type, int requestID )
    {
        userName       = user;
        clientName     = client;
        this.requestID = requestID;
        this.type      = type;
        payload        = null;
        
        indicatesUpdateConnection = false;
    }
    
    public String getUserName() { return userName; }
    public String getClientName() { return clientName; }
    public String getType() { return type; }
    public int getRequestID() { return requestID; }
    
    public void setPayload( Object payload )
    {
        this.payload = payload;
    }
    
    public Object getPayLoad() { return payload; }
    
    public void indicateUpdateConnection( boolean isUpdate )
    {
        indicatesUpdateConnection = isUpdate;
    }
    
    public boolean isUpdateConnection() { return indicatesUpdateConnection; }
    
    
    public String toString()
    {
        return "action message: " + userName + ", " + clientName + ", " + type + ", " + requestID;
    }
}
